import api from '../../api';
import { message } from 'antd';
export default {
  namespace: 'cashOrderM',

  state: {},
  effects: {
    //查看产品下拉列表
    *queryProductIdList({ payload, callback }, { call, put }) {
      const response = yield call(api.cashOrder.queryProductList, payload);
      if (response) {
        if (response.code == 0) {
          callback('success', response.data || []);
        } else {
          callback('fail');
          message.error(response.msg || '查询产品下拉列表失败!');
        }
      } else {
        callback('fail');
        message.error('查询产品下拉列表失败!');
      }
    },
    // 交易录入
    *tradeEntry({ payload, callback }, { call, put }) {
      const response = yield call(api.cashOrder.tradeEntry, payload);
      if (response) {
        if (response.code == 0) {
          callback('success', response.data || []);
          message.success(response.msg || '交易录入成功!');
        } else {
          callback('fail');
          message.error(response.msg || '交易录入失败!');
        }
      } else {
        callback('fail');
        message.error('交易录入失败!');
      }
    },
    reducers: {
      save(state, { payload }) {
        return {
          ...state,
          ...payload,
        };
      },
    },
  },
};
